﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Xwork.SEO.WebSite
{
    internal class SEOHandleErrorAttribute : HandleErrorAttribute
    {
        public override void OnException(ExceptionContext filterContext)
        {
            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                if (!filterContext.IsChildAction)
                {
                    filterContext.ExceptionHandled = true;
                    filterContext.Result = new JsonResult()
                    {
                        ContentType = "application/json",
                        Data = new { error = filterContext.Exception.Message },
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    };
                }
            }
            base.OnException(filterContext);
        }

    }
}